package homework.exp04;

import java.util.Scanner;
import java.util.Stack;

public class C {
    static String[][] LL1_TABLE = new String[][]{{"Te", "null", "Te", "null", "null", "null"}, {"null", "#", "null", "+Te", "null", "#"}, {"Ft", "null", "Ft", "null", "null", "null"}, {"nill", "#", "null", "#", "*Ft", "#"}, {"(E)", "null", "i", "null", "null", "null"}};
    static String Vt = "()i+*#";
    static String Vn = "EeTtF";

    static Scanner cin = new Scanner(System.in);

    //查找终结符Vt
    static int findVt(char c) {
        for (int i = 0; i < Vt.length(); i++) {
            if (c == Vt.charAt(i)) {
                return i;
            }
        }
        return -1;
    }

    //查找非终结符Vn
    static int findVn(char c) {
        for (int i = 0; i < Vn.length(); i++) {
            if (c == Vn.charAt(i)) {
                return i;
            }
        }
        return -1;
    }
    //LL1分析
    static boolean parse(String s) {
        Stack<Character> st = new Stack<>();
        st.push('#');
        st.push('E');
        int n = s.length();
        for (int i = 0; i < n; i++) {//s=x1x2...xn 全为终结符
            int index = findVt(s.charAt(i));
            if (index == -1) {
                return false;
            } else {
                //X ->(*) ..s[i]..
                while (!st.empty() && st.peek() != s.charAt(i)) {
                    int index1 = findVn(st.peek());
                    if (index1 == -1) {
                        return false;
                    } else {//当前非终节符要变为终结符s[i] 根据first函数 Vn -> Vt
                        String p = LL1_TABLE[index1][index];
                        if (p.equals("null")) {
                            return false;
                        } else if (p.equals("#")) {
                            st.pop();
                        } else {
                            st.pop();
                            for (int j = p.length() - 1; j >= 0; j--) {
                                st.push(p.charAt(j));
                            }
                        }
                    }
                }
                if (st.peek() == s.charAt(i)) {
                    if (s.charAt(i) == '#') {
                        return true;
                    } else {
                        st.pop();
                    }
                } else {

                    return false;
                }
            }
        }
        return false;
    }

    public static void main(String[] args) {
        while (cin.hasNext()) {
            String word = cin.nextLine();
            if (parse(word)) {
                System.out.println("syntax correct");
            } else {
                System.out.println("syntax error");
            }
        }

    }
}
